package fangzhiyi_day0321.homework.business;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author fangzhiyi
 * @version 1.0
 * @date 2025/3/21 18:42
 * @description
 */
public class Test {
    static  Scanner input = new Scanner(System.in);
    static  ArrayList<Dep> deps = new ArrayList<Dep>();
    static  ArrayList<Emp> emp = new ArrayList<Emp>();

     static {
        deps.add(new Dep(1,"后勤部","洗衣拖地很在行",150355277));
        deps.add(new Dep(2,"研发部","用于研发高新技术",150355377));
        deps.add(new Dep(3,"财务部","天大地大，财务最大",150355477));

        emp.add(new Emp(101,"南风","男","程序员",18,6000,"研发部"));
        emp.add(new Emp(102,"知我意","男","程序员",19,8000,"研发部"));
        emp.add(new Emp(103,"桐桐","女","程序员",18,12000,"研发部"));
        emp.add(new Emp(201,"小南","男","保洁",18,4000,"后勤部"));
        emp.add(new Emp(202,"小风","男","保洁",18,4000,"后勤部"));
        emp.add(new Emp(203,"小桐","男","保洁",18,4000,"后勤部"));
        emp.add(new Emp(301,"方知意","男","财务经理",20,12000,"财务部"));

    }

    public static void main(String[] args) {

        while (true){
            System.out.println("=========================================");
            System.out.println("1.查询所有员工信息和所在部门信息");
            System.out.println("2.根据员工工号显示员工信息");
            System.out.println("3.修改指定工号员工的薪资");
            System.out.println("4.根据部门号查询出部门中的所有员工");
            System.out.println("5.结束");
            System.out.println("==========================================");
            System.out.println("请输入你的选择");
            int num = input.nextInt();
            switch (num){
                case 1:
                    find();
                    break;
                case 2:
                    showEmp();
                    break;
                case 3:
                    setEmp();
                    break;
                case 4:
                    findSector();
                    break;
                default:
                    System.exit(0);
            }
        }

    }


    public static void find(){
        for (int i = 0; i < emp.size(); i++) {
            for (int j = 0; j < deps.size(); j++) {
                if (emp.get(i).getSector().equals(deps.get(j).getDepName())){
                    System.out.println(emp.get(i)+"===="+deps.get(j));
                }
            }
        }
    }

    public static void showEmp(){
        System.out.println("请输入员工的工号");
        int id = input.nextInt();
        boolean flag = true;
        for (int i = 0; i < emp.size(); i++) {
            if (id==emp.get(i).getId()){
                System.out.println(emp.get(i));
            }else {
                flag = false;

            }
        }
        if (flag==false){
            System.out.println("你输入的工号不存在");
        }
    }

    public static void setEmp(){
        System.out.println("请输入要修改薪资的员工工号");
        int id = input.nextInt();
        for (int i = 0; i < emp.size(); i++) {
            if (id==emp.get(i).getId()){
                System.out.println("请输入要修改的薪资");
                int salary = input.nextInt();
                emp.get(i).setMonthSalary(salary);
                System.out.println(emp.get(i));
            }
        }
    }

    public static void findSector(){
        System.out.println("请输入需要查询的部门号");
        int sector = input.nextInt();
        for (int i = 0; i < deps.size(); i++) {
            if (sector==deps.get(i).getNumber()){
            for (int j = 0; j < emp.size(); j++) {
                  if (emp.get(j).getSector().equals(deps.get(i).getDepName())){
                      System.out.println(emp.get(j));
                  }
                }
            return;
            }
        }
        System.out.println("你输入的部门不存在");
        }


}
